home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / javax / swing / JFrame.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  31.1 KB  |  982 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)JFrame.java    1.59 98/09/29
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package javax.swing;
  15.  
  16. import java.awt.*;
  17. import java.awt.event.*;
  18. import java.beans.PropertyChangeListener;
  19. import java.util.Locale;
  20. import java.util.Vector;
  21. import java.io.Serializable;
  22.  
  23. import javax.accessibility.*;
  24.  
  25.  
  26. /**
  27.  * An extended version of java.awt.Frame that adds support for 
  28.  * interposing input and painting behavior in front of the frame's
  29.  * children (see glassPane), support for special children that 
  30.  * are managed by a LayeredPane (see rootPane) and for Swing MenuBars.
  31.  * <p>
  32.  * The JFrame class is slightly incompatible with java.awt.Frame.
  33.  * JFrame contains a JRootPane as it's only child.
  34.  * The <b>contentPane</b> should be the parent of any children of the JFrame.
  35.  * This is different than java.awt.Frame, e.g. to add a child to 
  36.  * an AWT Frame you'd write:
  37.  * <pre>
  38.  *       frame.add(child);
  39.  * </pre>
  40.  * However using JFrame you need to add the child to the JFrames contentPane
  41.  * instead:
  42.  * <pre>
  43.  *       frame.getContentPane().add(child);
  44.  * </pre>
  45.  * The same is true for setting LayoutManagers, removing components,
  46.  * listing children, etc. All these methods should normally be sent to
  47.  * the contentPane() instead of the JFrame itself. The contentPane() will
  48.  * always be non-null. Attempting to set it to null will cause the JFrame
  49.  * to throw an exception. The default contentPane() will have a BorderLayout
  50.  * manager set on it. 
  51.  * <p>
  52.  * Please see the JRootPane documentation for a complete description of
  53.  * the contentPane, glassPane, and layeredPane properties.
  54.  * <p>
  55.  * Unlike its parent class, java.awt.Frame, you can tell a JFrame how to 
  56.  * respond when the user attempts to close the window. The default behavior
  57.  * is to simply hide the JFrame when the user closes the window. To change the
  58.  * default behavior, you invoke the method <code>setDefaultCloseOperation</code>.
  59.  * To make the JFrame remain open unless you handle the window-closing event and 
  60.  * explicitly invoke <code>dispose()</code> (or exit the app, which is also pretty
  61.  * effective), use
  62.  * <code>setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)</code>.
  63.  * That makes the JFrame behave the same as java.awt.Frame. A third option
  64.  * lets you completely dispose of the window when it closes, instead of merely 
  65.  * hiding it. 
  66.  * <p>
  67.  * For the keyboard keys used by this component in the standard Look and
  68.  * Feel (L&F) renditions, see the
  69.  * <a href="doc-files/Key-Index.html#JFrame">JFrame</a> key assignments.
  70.  * <p>
  71.  * <strong>Warning:</strong>
  72.  * Serialized objects of this class will not be compatible with 
  73.  * future Swing releases.  The current serialization support is appropriate
  74.  * for short term storage or RMI between applications running the same
  75.  * version of Swing.  A future release of Swing will provide support for
  76.  * long term persistence.
  77.  *
  78.  * @see JRootPane
  79.  * @see #setDefaultCloseOperation
  80.  * @see java.awt.event.WindowListener#windowClosing
  81.  *
  82.  * @beaninfo
  83.  *      attribute: isContainer true
  84.  *      attribute: containerDelegate getContentPane
  85.  *    description: A toplevel window which can be minimized to an icon.
  86.  *
  87.  * @version 1.59 09/29/98
  88.  * @author Jeff Dinkins
  89.  * @author Georges Saab
  90.  * @author David Kloba
  91.  */
  92. public class JFrame  extends Frame implements WindowConstants, Accessible, RootPaneContainer
  93. {
  94.     private int defaultCloseOperation = HIDE_ON_CLOSE;
  95.  
  96.     /**
  97.      * The JRootPane instance that manages the <code>contentPane</code> 
  98.      * and optional <code>menuBar</code> for this frame, as well as the 
  99.      * <code>glassPane</code>.
  100.      *
  101.      * @see JRootPane
  102.      * @see RootPaneContainer
  103.      */
  104.     protected JRootPane rootPane;
  105.  
  106.     /**
  107.      * If true then calls to <code>add</code> and <code>setLayout</code>
  108.      * cause an exception to be thrown.
  109.      *
  110.      * @see #isRootPaneCheckingEnabled
  111.      * @see #setRootPaneCheckingEnabled
  112.      */
  113.     protected boolean rootPaneCheckingEnabled = false;
  114.  
  115.  
  116.     /**
  117.      * Constructs a new Frame that is initially invisible.
  118.      *
  119.      * @see Component#setSize
  120.      * @see Component#setVisible
  121.      */
  122.     public JFrame() {
  123.         super();        
  124.         frameInit();
  125.     }
  126.  
  127.     /**
  128.      * Constructs a new, initially invisible Frame with the specified
  129.      * title.
  130.      *
  131.      * @param title the title for the frame
  132.      * @see Component#setSize
  133.      * @see Component#setVisible
  134.      */
  135.     public JFrame(String title) {
  136.         super(title);
  137.         frameInit();
  138.     }
  139.  
  140.     /** Called by the constructors to init the JFrame properly. */
  141.     protected void frameInit() {
  142.         enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK);
  143.         /*if[JDK1.2]
  144.           // workaround for bug 4170760
  145.           enableInputMethods(false);
  146.         /*end[JDK1.2]*/
  147.         setRootPane(createRootPane());
  148.         setBackground(UIManager.getColor("control"));
  149.         setRootPaneCheckingEnabled(true);
  150.     }
  151.  
  152.     /** Called by the constructor methods to create the default rootPane. */
  153.     protected JRootPane createRootPane() {
  154.         return new JRootPane();
  155.     }
  156.  
  157.     /** 
  158.      * Processes key events occurring on this component and, if appropriate,
  159.      * passes them on to components in the frame which have registered 
  160.      * interest in them.
  161.      *
  162.      * @param  e  the key event
  163.      * @see    java.awt.Component#processKeyEvent
  164.      */   
  165.     protected void processKeyEvent(KeyEvent e) {
  166.         super.processKeyEvent(e);
  167.         if(!e.isConsumed()) {
  168.             JComponent.processKeyBindingsForAllComponents(e,this,e.getID() == KeyEvent.KEY_PRESSED);
  169.         }
  170.     }
  171.  
  172.     /** 
  173.      * Processes window events occurring on this component.
  174.      * Hides the window or disposes of it, as specified by the setting
  175.      * of the <code>defaultCloseOperation</code> property.
  176.      *
  177.      * @param  e  the window event
  178.      * @see    #setDefaultCloseOperation
  179.      * @see    java.awt.Window#processWindowEvent
  180.      */
  181.     protected void processWindowEvent(WindowEvent e) {
  182.         super.processWindowEvent(e);
  183.  
  184.         if (e.getID() == WindowEvent.WINDOW_CLOSING) {
  185.             switch(defaultCloseOperation) {
  186.               case HIDE_ON_CLOSE:
  187.                  setVisible(false);
  188.                  break;
  189.               case DISPOSE_ON_CLOSE:
  190.                  setVisible(false);
  191.                  dispose();
  192.                  break;
  193.               case DO_NOTHING_ON_CLOSE:
  194.                  default: 
  195.                  break;
  196.             }
  197.         }
  198.     }
  199.  
  200. //    public void setMenuBar(MenuBar menu) {  
  201. //        throw new IllegalComponentStateException("Please use setJMenuBar() with JFrame.");
  202. //    }
  203.  
  204.     /**                   
  205.      * Sets the operation which will happen by default when
  206.      * the user initiates a "close" on this frame.
  207.      * The possible choices are defined in the <code>WindowConstants</code>
  208.      * interface:
  209.      * <p>
  210.      * <ul>
  211.      * <li>DO_NOTHING_ON_CLOSE - do not do anything - require the
  212.      * program to handle the operation in the windowClosing
  213.      * method of a registered WindowListener object.
  214.      * <li>HIDE_ON_CLOSE - automatically hide the frame after
  215.      * invoking any registered WindowListener objects
  216.      * <li>DISPOSE_ON_CLOSE - automatically hide and dispose the 
  217.      * frame after invoking any registered WindowListener objects
  218.      * </ul>
  219.      * <p>
  220.      * The value is set to HIDE_ON_CLOSE by default.
  221.      * @see #addWindowListener
  222.      * @see #getDefaultCloseOperation
  223.      *
  224.      * @beaninfo
  225.      *   preferred: true
  226.      *        enum: DO_NOTHING_ON_CLOSE WindowConstants.DO_NOTHING_ON_CLOSE
  227.      *              HIDE_ON_CLOSE       WindowConstants.HIDE_ON_CLOSE
  228.      *              DISPOSE_ON_CLOSE    WindowConstants.DISPOSE_ON_CLOSE
  229.      * description: The frame's default close operation.
  230.      */
  231.     public void setDefaultCloseOperation(int operation) {
  232.         this.defaultCloseOperation = operation;
  233.     }
  234.  
  235.  
  236.    /**
  237.     * Returns the operation which occurs when the user
  238.     * initiates a "close" on this frame.
  239.     *
  240.     * @return an int indicating the window-close operation
  241.     * @see #setDefaultCloseOperation
  242.     */
  243.     public int getDefaultCloseOperation() {
  244.         return defaultCloseOperation;
  245.     }
  246.  
  247.  
  248.     /** 
  249.      * Just calls <code>paint(g)</code>.  This method was overridden to 
  250.      * prevent an unneccessary call to clear the background.
  251.      *
  252.      * @param g the Graphics context in which to paint
  253.      */
  254.     public void update(Graphics g) {
  255.         paint(g);
  256.     }
  257.  
  258.    /**
  259.     * Sets the menubar for this frame.
  260.     * @param menubar the menubar being placed in the frame
  261.     *
  262.     * @see #getJMenuBar
  263.     *
  264.     * @beaninfo
  265.     *      hidden: true
  266.     * description: The menubar for accessing pulldown menus from this frame.
  267.     */
  268.     public void setJMenuBar(JMenuBar menubar) {
  269.         getRootPane().setMenuBar(menubar);
  270.     }
  271.  
  272.    /**
  273.     * Returns the menubar set on this frame.
  274.     *
  275.     * @see #setJMenuBar
  276.     */
  277.     public JMenuBar getJMenuBar() { 
  278.         return getRootPane().getMenuBar(); 
  279.     }
  280.  
  281.     /**
  282.      * Returns whether calls to <code>add</code> and 
  283.      * <code>setLayout</code> cause an exception to be thrown. 
  284.      *
  285.      * @return true if <code>add</code> and <code>setLayout</code> 
  286.      *         are checked
  287.      *
  288.      * @see #addImpl
  289.      * @see #setLayout
  290.      * @see #setRootPaneCheckingEnabled
  291.      */
  292.     protected boolean isRootPaneCheckingEnabled() {
  293.         return rootPaneCheckingEnabled;
  294.     }
  295.  
  296.  
  297.     /**
  298.      * Determines whether calls to <code>add</code> and 
  299.      * <code>setLayout</code> cause an exception to be thrown. 
  300.      * 
  301.      * @param enabled  a boolean value, true if checking is to be
  302.      *        enabled, which cause the exceptions to be thrown
  303.      *
  304.      * @see #addImpl
  305.      * @see #setLayout
  306.      * @see #isRootPaneCheckingEnabled
  307.      * @beaninfo
  308.      *      hidden: true
  309.      * description: Whether the add and setLayout methods throw exceptions when invoked.
  310.      */
  311.     protected void setRootPaneCheckingEnabled(boolean enabled) {
  312.         rootPaneCheckingEnabled = enabled;
  313.     }
  314.  
  315.  
  316.     /**
  317.      * Creates a runtime exception with a message like:
  318.      * <pre>
  319.      * "Do not use JFrame.add() use JFrame.getContentPane().add() instead"
  320.      * </pre>
  321.      *
  322.      * @param op  a String indicating the attempted operation. In the
  323.      *            example above, the operation string is "add"
  324.      */
  325.     private Error createRootPaneException(String op) {
  326.         String type = getClass().getName();
  327.         return new Error(
  328.             "Do not use " + type + "." + op + "() use " 
  329.                           + type + ".getContentPane()." + op + "() instead");
  330.     }
  331.  
  332.  
  333.     /**
  334.      * By default, children may not be added directly to a this component,
  335.      * they must be added to its contentPane instead.  For example:
  336.      * <pre>
  337.      * thisComponent.getContentPane().add(child)
  338.      * </pre>
  339.      * An attempt to add to directly to this component will cause an
  340.      * runtime exception to be thrown.  Subclasses can disable this
  341.      * behavior.
  342.      * 
  343.      * @see #setRootPaneCheckingEnabled
  344.      * @exception Error if called with rootPaneChecking true
  345.      */
  346.     protected void addImpl(Component comp, Object constraints, int index) 
  347.     {
  348.         if(isRootPaneCheckingEnabled()) {
  349.             throw createRootPaneException("add");
  350.         }
  351.         else {
  352.             super.addImpl(comp, constraints, index);
  353.         }
  354.     }
  355.  
  356.  
  357.     /**
  358.      * By default the layout of this component may not be set,
  359.      * the layout of its contentPane should be set instead.  
  360.      * For example:
  361.      * <pre>
  362.      * thiComponent.getContentPane().setLayout(new BorderLayout())
  363.      * </pre>
  364.      * An attempt to set the layout of this component will cause an
  365.      * runtime exception to be thrown.  Subclasses can disable this
  366.      * behavior.
  367.      * 
  368.      * @see #setRootPaneCheckingEnabled
  369.      * @exception Error if called with rootPaneChecking true
  370.      */
  371.     public void setLayout(LayoutManager manager) {
  372.         if(isRootPaneCheckingEnabled()) {
  373.             throw createRootPaneException("setLayout");
  374.         }
  375.         else {
  376.             super.setLayout(manager);
  377.         }
  378.     }
  379.  
  380.  
  381.     /**
  382.      * Returns the rootPane object for this frame.
  383.      *
  384.      * @see #setRootPane
  385.      * @see RootPaneContainer#getRootPane
  386.      */
  387.     public JRootPane getRootPane() { 
  388.         return rootPane; 
  389.     }
  390.  
  391.  
  392.     /**
  393.      * Sets the rootPane property.  This method is called by the constructor.
  394.      * @param root the rootPane object for this frame
  395.      *
  396.      * @see #getRootPane
  397.      *
  398.      * @beaninfo
  399.      *   hidden: true
  400.      * description: the RootPane object for this frame.
  401.      */
  402.     protected void setRootPane(JRootPane root) 
  403.     {
  404.         if(rootPane != null) {
  405.             remove(rootPane);
  406.         }
  407.         rootPane = root;
  408.         if(rootPane != null) {
  409.             boolean checkingEnabled = isRootPaneCheckingEnabled();
  410.             try {
  411.                 setRootPaneCheckingEnabled(false);
  412.                 add(rootPane, BorderLayout.CENTER);
  413.             }
  414.             finally {
  415.                 setRootPaneCheckingEnabled(checkingEnabled);
  416.             }
  417.         }
  418.     }
  419.  
  420.  
  421.     /**
  422.      * Returns the contentPane object for this frame.
  423.      *
  424.      * @see #setContentPane
  425.      * @see RootPaneContainer#getContentPane
  426.      */
  427.     public Container getContentPane() { 
  428.         return getRootPane().getContentPane(); 
  429.     }
  430.  
  431.     /**
  432.      * Sets the contentPane property.  This method is called by the constructor.
  433.      * @param contentPane the contentPane object for this frame
  434.      *
  435.      * @exception java.awt.IllegalComponentStateException (a runtime
  436.      *            exception) if the content pane parameter is null
  437.      * @see #getContentPane
  438.      * @see RootPaneContainer#setContentPane
  439.      *
  440.      * @beaninfo
  441.      *     hidden: true
  442.      *     description: The client area of the frame where child 
  443.      *                  components are normally inserted.
  444.      */
  445.     public void setContentPane(Container contentPane) {
  446.         getRootPane().setContentPane(contentPane);
  447.     }
  448.  
  449.     /**
  450.      * Returns the layeredPane object for this frame.
  451.      *
  452.      * @see #setLayeredPane
  453.      * @see RootPaneContainer#getLayeredPane
  454.      */
  455.     public JLayeredPane getLayeredPane() { 
  456.         return getRootPane().getLayeredPane(); 
  457.     }
  458.  
  459.     /**
  460.      * Sets the layeredPane property.  This method is called by the constructor.
  461.      * @param layeredPane the layeredPane object for this frame
  462.      *
  463.      * @exception java.awt.IllegalComponentStateException (a runtime
  464.      *            exception) if the layered pane parameter is null
  465.      * @see #getLayeredPane
  466.      * @see RootPaneContainer#setLayeredPane
  467.      *
  468.      * @beaninfo
  469.      *     hidden: true
  470.      *     description: The pane which holds the various frame layers.
  471.      */
  472.     public void setLayeredPane(JLayeredPane layeredPane) {
  473.         getRootPane().setLayeredPane(layeredPane);
  474.     }
  475.  
  476.     /**
  477.      * Returns the glassPane object for this frame.
  478.      *
  479.      * @see #setGlassPane
  480.      * @see RootPaneContainer#getGlassPane
  481.      */
  482.     public Component getGlassPane() { 
  483.         return getRootPane().getGlassPane(); 
  484.     }
  485.  
  486.     /**
  487.      * Sets the glassPane property. 
  488.      * This method is called by the constructor.
  489.      * @param glassPane the glassPane object for this frame
  490.      *
  491.      * @see #getGlassPane
  492.      * @see RootPaneContainer#setGlassPane
  493.      *
  494.      * @beaninfo
  495.      *     hidden: true
  496.      *     description: A transparent pane used for menu rendering.
  497.      */
  498.     public void setGlassPane(Component glassPane) {
  499.         getRootPane().setGlassPane(glassPane);
  500.     }
  501.  
  502.  
  503.     /**
  504.      * Returns a string representation of this JFrame. This method 
  505.      * is intended to be used only for debugging purposes, and the 
  506.      * content and format of the returned string may vary between      
  507.      * implementations. The returned string may be empty but may not 
  508.      * be <code>null</code>.
  509.      * <P>
  510.      * Overriding paramString() to provide information about the
  511.      * specific new aspects of the JFC components.
  512.      * 
  513.      * @return  a string representation of this JFrame.
  514.      */
  515.     protected String paramString() {
  516.         String defaultCloseOperationString;
  517.         if (defaultCloseOperation == HIDE_ON_CLOSE) {
  518.             defaultCloseOperationString = "HIDE_ON_CLOSE";
  519.         } else if (defaultCloseOperation == DISPOSE_ON_CLOSE) {
  520.             defaultCloseOperationString = "DISPOSE_ON_CLOSE";
  521.         } else if (defaultCloseOperation == DO_NOTHING_ON_CLOSE) {
  522.             defaultCloseOperationString = "DO_NOTHING_ON_CLOSE";
  523.         } else defaultCloseOperationString = "";
  524.     String rootPaneString = (rootPane != null ?
  525.                  rootPane.toString() : "");
  526.     String rootPaneCheckingEnabledString = (rootPaneCheckingEnabled ?
  527.                         "true" : "false");
  528.  
  529.     return super.paramString() +
  530.     ",defaultCloseOperation=" + defaultCloseOperationString +
  531.     ",rootPane=" + rootPaneString +
  532.     ",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString;
  533.     }
  534.  
  535.  
  536.  
  537. /////////////////
  538. // Accessibility support
  539. ////////////////
  540.  
  541.     /** The accessible context property */
  542.     protected AccessibleContext accessibleContext = null;
  543.  
  544.     /**
  545.      * Get the AccessibleContext associated with this JFrame
  546.      *
  547.      * @return the AccessibleContext of this JFrame
  548.      */
  549.     public AccessibleContext getAccessibleContext() {
  550.         if (accessibleContext == null) {
  551.             accessibleContext = new AccessibleJFrame();
  552.         }
  553.         return accessibleContext;
  554.     }
  555.  
  556.     /**
  557.      * The class used to obtain the AccessibleRole for this object.
  558.      */
  559.     protected class AccessibleJFrame extends AccessibleContext
  560.         implements Serializable, AccessibleComponent {
  561.  
  562.         // AccessibleContext methods
  563.         /**
  564.          * Get the accessible name of this object.  
  565.          *
  566.          * @return the localized name of the object -- can be null if this 
  567.          * object does not have a name
  568.          */
  569.         public String getAccessibleName() {
  570.             if (accessibleName != null) {
  571.                 return accessibleName;
  572.             } else {
  573.                 if (getTitle() == null) {
  574.                     return super.getAccessibleName();
  575.                 } else {
  576.                     return getTitle();
  577.                 }
  578.             }
  579.         }
  580.  
  581.         /**
  582.          * Get the role of this object.
  583.          *
  584.          * @return an instance of AccessibleRole describing the role of the 
  585.          * object
  586.          * @see AccessibleRole
  587.          */
  588.         public AccessibleRole getAccessibleRole() {
  589.             return AccessibleRole.FRAME;
  590.         }
  591.  
  592.         /**
  593.          * Get the state of this object.
  594.          *
  595.          * @return an instance of AccessibleStateSet containing the current 
  596.          * state set of the object
  597.          * @see AccessibleState
  598.          */
  599.         public AccessibleStateSet getAccessibleStateSet() {
  600.             AccessibleStateSet states = SwingUtilities.getAccessibleStateSet(JFrame.this);
  601.             if (isResizable()) {
  602.                 states.add(AccessibleState.RESIZABLE);
  603.             }
  604.             if (getFocusOwner() != null) {
  605.                 states.add(AccessibleState.ACTIVE);
  606.             }   
  607.             // FIXME:  [[[WDW - should also return ICONIFIED and ICONIFIABLE
  608.             // if we can ever figure these out]]]
  609.             return states;
  610.         }
  611.  
  612.         /**
  613.          * Get the Accessible parent of this object.  If the parent of this
  614.          * object implements Accessible, this method should simply return
  615.          * getParent().
  616.          *
  617.          * @return the Accessible parent of this object -- can be null if this
  618.          * object does not have an Accessible parent
  619.          */
  620.         public Accessible getAccessibleParent() {
  621.         if (accessibleParent != null) {
  622.         return accessibleParent;
  623.         } else {
  624.                 Container parent = getParent();
  625.                 if (parent instanceof Accessible) {
  626.                     return (Accessible) parent;
  627.         }
  628.             }
  629.             return null;
  630.         }
  631.  
  632.         /**
  633.          * Get the index of this object in its accessible parent. 
  634.          *
  635.          * @return the index of this object in its parent; -1 if this 
  636.          * object does not have an accessible parent.
  637.          * @see #getAccessibleParent
  638.          */
  639.         public int getAccessibleIndexInParent() {
  640.             return SwingUtilities.getAccessibleIndexInParent(JFrame.this);
  641.         }
  642.  
  643.         /**
  644.          * Returns the number of accessible children in the object.  If all
  645.          * of the children of this object implement Accessible, than this
  646.          * method should return the number of children of this object.
  647.          *
  648.          * @return the number of accessible children in the object.
  649.          */
  650.         public int getAccessibleChildrenCount() {
  651.             return SwingUtilities.getAccessibleChildrenCount(JFrame.this);
  652.         }
  653.  
  654.         /**
  655.          * Return the nth Accessible child of the object.  
  656.          *
  657.          * @param i zero-based index of child
  658.          * @return the nth Accessible child of the object
  659.          */
  660.         public Accessible getAccessibleChild(int i) {
  661.             return SwingUtilities.getAccessibleChild(JFrame.this,i);
  662.         }
  663.  
  664.         /**
  665.          * Return the locale of this object.
  666.          *
  667.          * @return the locale of this object
  668.          */
  669.         public Locale getLocale() {
  670.             return JFrame.this.getLocale();
  671.         }
  672.  
  673.         /**
  674.          * Get the AccessibleComponent associated with this object if one
  675.          * exists.  Otherwise return null.
  676.          */
  677.         public AccessibleComponent getAccessibleComponent() {
  678.             return this;
  679.         }
  680.  
  681.  
  682.         // AccessibleComponent methods
  683.         //
  684.         /**
  685.          * Get the background color of this object.
  686.          *
  687.          * @return the background color, if supported, of the object; 
  688.          * otherwise, null
  689.          */
  690.         public Color getBackground() {
  691.             return JFrame.this.getBackground();
  692.         }
  693.  
  694.         /**
  695.          * Set the background color of this object.
  696.          *
  697.          * @param c the new Color for the background
  698.          */
  699.         public void setBackground(Color c) {
  700.             JFrame.this.setBackground(c);
  701.         }
  702.  
  703.         /**
  704.          * Get the foreground color of this object.
  705.          *
  706.          * @return the foreground color, if supported, of the object; 
  707.          * otherwise, null
  708.          */
  709.         public Color getForeground() {
  710.             return JFrame.this.getForeground();
  711.         }
  712.  
  713.         /**
  714.          * Set the foreground color of this object.
  715.          *
  716.          * @param c the new Color for the foreground
  717.          */
  718.         public void setForeground(Color c) {
  719.             JFrame.this.setForeground(c);
  720.         }
  721.  
  722.         /**
  723.          * Get the Cursor of this object.
  724.          *
  725.          * @return the Cursor, if supported, of the object; otherwise, null
  726.          */
  727.         public Cursor getCursor() {
  728.             return JFrame.this.getCursor();
  729.         }
  730.  
  731.         /**
  732.          * Set the Cursor of this object.
  733.          *
  734.          * @param c the new Cursor for the object
  735.          */
  736.         public void setCursor(Cursor cursor) {
  737.             JFrame.this.setCursor(cursor);
  738.         }
  739.  
  740.         /**
  741.          * Get the Font of this object.
  742.          *
  743.          * @return the Font,if supported, for the object; otherwise, null
  744.          */
  745.         public Font getFont() {
  746.             return JFrame.this.getFont();
  747.         }
  748.  
  749.         /**
  750.          * Set the Font of this object.
  751.          *
  752.          * @param f the new Font for the object
  753.          */
  754.         public void setFont(Font f) {
  755.             JFrame.this.setFont(f);
  756.         }
  757.  
  758.         /**
  759.          * Get the FontMetrics of this object.
  760.          *
  761.          * @param f the Font
  762.          * @return the FontMetrics, if supported, the object; otherwise, null
  763.          * @see getFont
  764.          */
  765.         public FontMetrics getFontMetrics(Font f) {
  766.             return JFrame.this.getFontMetrics(f);
  767.         }
  768.  
  769.         /**
  770.          * Determine if the object is enabled.
  771.          *
  772.          * @return true if object is enabled; otherwise, false
  773.          */
  774.         public boolean isEnabled() {
  775.             return JFrame.this.isEnabled();
  776.         }
  777.  
  778.         /**
  779.          * Set the enabled state of the object.
  780.          *
  781.          * @param b if true, enables this object; otherwise, disables it 
  782.          */
  783.         public void setEnabled(boolean b) {
  784.             JFrame.this.setEnabled(b);
  785.         }
  786.         
  787.         /**
  788.          * Determine if the object is visible.  Note: this means that the
  789.          * object intends to be visible; however, it may not in fact be
  790.          * showing on the screen because one of the objects that this object
  791.          * is contained by is not visible.  To determine if an object is
  792.          * showing on the screen, use isShowing().
  793.          *
  794.          * @return true if object is visible; otherwise, false
  795.          */
  796.         public boolean isVisible() {
  797.             return JFrame.this.isVisible();
  798.         }
  799.  
  800.         /**
  801.          * Set the visible state of the object.
  802.          *
  803.          * @param b if true, shows this object; otherwise, hides it 
  804.          */
  805.         public void setVisible(boolean b) {
  806.             JFrame.this.setVisible(b);
  807.         }
  808.  
  809.         /**
  810.          * Determine if the object is showing.  This is determined by checking
  811.          * the visibility of the object and ancestors of the object.  Note: 
  812.          * this will return true even if the object is obscured by another 
  813.          * (for example, it happens to be underneath a menu that was pulled 
  814.          * down).
  815.          *
  816.          * @return true if object is showing; otherwise, false
  817.          */
  818.         public boolean isShowing() {
  819.             return JFrame.this.isShowing();
  820.         }
  821.  
  822.         /** 
  823.          * Checks whether the specified point is within this object's bounds,
  824.          * where the point's x and y coordinates are defined to be relative to 
  825.          * the coordinate system of the object. 
  826.          *
  827.          * @param p the Point relative to the coordinate system of the object
  828.          * @return true if object contains Point; otherwise false
  829.          */
  830.         public boolean contains(Point p) {
  831.             return JFrame.this.contains(p);
  832.         }
  833.     
  834.         /** 
  835.          * Returns the location of the object on the screen.
  836.          *
  837.          * @return location of object on screen -- can be null if this object
  838.          * is not on the screen
  839.          */
  840.         public Point getLocationOnScreen() {
  841.             return JFrame.this.getLocationOnScreen();
  842.         }
  843.  
  844.         /** 
  845.          * Gets the location of the object relative to the parent in the form 
  846.          * of a point specifying the object's top-left corner in the screen's 
  847.          * coordinate space.
  848.          *
  849.          * @return An instance of Point representing the top-left corner of 
  850.          * the objects's bounds in the coordinate space of the screen; null if
  851.          * this object or its parent are not on the screen
  852.          */
  853.         public Point getLocation() {
  854.             return JFrame.this.getLocation();
  855.         }
  856.  
  857.         /** 
  858.          * Sets the location of the object relative to the parent.
  859.          */
  860.         public void setLocation(Point p) {
  861.             JFrame.this.setLocation(p);
  862.         }
  863.  
  864.         /** 
  865.          * Gets the bounds of this object in the form of a Rectangle object. 
  866.          * The bounds specify this object's width, height, and location
  867.          * relative to its parent. 
  868.          *
  869.          * @return A rectangle indicating this component's bounds; null if 
  870.          * this object is not on the screen.
  871.          */
  872.         public Rectangle getBounds() {
  873.             return JFrame.this.getBounds();
  874.         }
  875.  
  876.         /** 
  877.          * Sets the bounds of this object in the form of a Rectangle object. 
  878.          * The bounds specify this object's width, height, and location
  879.          * relative to its parent.
  880.          *      
  881.          * @param A rectangle indicating this component's bounds
  882.          */
  883.         public void setBounds(Rectangle r) {
  884.             JFrame.this.setBounds(r);
  885.         }
  886.  
  887.         /** 
  888.          * Returns the size of this object in the form of a Dimension object. 
  889.          * The height field of the Dimension object contains this objects's
  890.          * height, and the width field of the Dimension object contains this 
  891.          * object's width. 
  892.          *
  893.          * @return A Dimension object that indicates the size of this 
  894.          * component; null if this object is not on the screen
  895.          */
  896.         public Dimension getSize() {
  897.             return JFrame.this.getSize();
  898.         }
  899.  
  900.         /** 
  901.          * Resizes this object so that it has width width and height. 
  902.          *      
  903.          * @param d - The dimension specifying the new size of the object. 
  904.          */
  905.         public void setSize(Dimension d) {
  906.             JFrame.this.setSize(d);
  907.         }
  908.  
  909.         /**
  910.          * Returns the Accessible child, if one exists, contained at the local
  911.          * coordinate Point.
  912.          *
  913.          * @param p The point defining the top-left corner of the Accessible, 
  914.          * given in the coordinate space of the object's parent. 
  915.          * @return the Accessible, if it exists, at the specified location; 
  916.          * else null
  917.          */
  918.         public Accessible getAccessibleAt(Point p) {
  919.             Accessible a;
  920.             AccessibleContext ac;
  921.             AccessibleComponent acmp;
  922.             Point location;
  923.             int nchildren = getAccessibleChildrenCount();
  924.             for (int i=0; i < nchildren; i++) {
  925.                 a = getAccessibleChild(i);
  926.                 if ((a != null)) {
  927.                     ac = a.getAccessibleContext();
  928.                     if (ac != null) {
  929.                         acmp = ac.getAccessibleComponent();
  930.                         if ((acmp != null) && (acmp.isShowing())) {
  931.                             location = acmp.getLocation();
  932.                             Point np = new Point(p.x-location.x, p.y-location.y)
  933. ;
  934.                             if (acmp.contains(np)){
  935.                                 return a;
  936.                             }
  937.                         }
  938.                     }
  939.                 }
  940.             }
  941.             return (Accessible) JFrame.this;
  942. //          return SwingUtilities.getAccessibleAt(JFrame.this,p);
  943.         }
  944.  
  945.         /**
  946.          * Returns whether this object can accept focus or not.
  947.          *
  948.          * @return true if object can accept focus; otherwise false
  949.          */
  950.         public boolean isFocusTraversable() {
  951.             return JFrame.this.isFocusTraversable();
  952.         }
  953.  
  954.         /**
  955.          * Requests focus for this object.
  956.          */
  957.         public void requestFocus() {
  958.             JFrame.this.requestFocus();
  959.         }
  960.  
  961.         /**
  962.          * Adds the specified focus listener to receive focus events from this 
  963.          * component. 
  964.          *
  965.          * @param l the focus listener
  966.          */
  967.         public void addFocusListener(FocusListener l) {
  968.             JFrame.this.addFocusListener(l);
  969.         }
  970.  
  971.         /**
  972.          * Removes the specified focus listener so it no longer receives focus 
  973.          * events from this component.
  974.          *
  975.          * @param l the focus listener
  976.          */
  977.         public void removeFocusListener(FocusListener l) {
  978.             JFrame.this.removeFocusListener(l);
  979.         }
  980.     } // inner class AccessibleJFrame
  981. }
  982.